package com.viewsky.base.back.controller.customer;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.viewsky.base.back.bean.LoginUser;
import com.viewsky.base.back.bean.Result;
import com.viewsky.base.back.controller.BaseController;
import com.viewsky.base.back.service.customer.ExampleService;
import com.viewsky.base.back.util.Constant;

@RestController
public class ExampleController extends BaseController
{	
	@Resource(name="exampleService")
	private ExampleService exampleService;
	
	@PostMapping(value="/my-customer")
	public Result getMyCustomer(@RequestBody Map<String, String> mapParam)throws Exception
	{		
		Result result = new Result();
				
		try
		{	
			LoginUser loginUser = getUser();
			
			Map<String, Object> MapResult = exampleService.getMyCustomer(
					mapParam, loginUser);

			result.setServer(getServer());
			result.setCode(Constant.ResultCode.SUCCESS);
			result.setData(MapResult);
		}
		catch(Exception e)
		{
			String strMessage = "服务器：" + getServer() +
					"，POST方式/my-customer，" +
					"获取我的客户报错：" + e.toString();
			
			logger.error(strMessage);			
			throw new Exception(strMessage);
		}
		
		return result;
	}
	
	@PostMapping(value="/test-batch")
	public Result testBatch()throws Exception
	{		
		Result result = new Result();
				
		try
		{
			String Message = exampleService.testBatch();
			
			result.setServer(getServer());
			result.setCode(Constant.ResultCode.SUCCESS);
			result.setData(Message);
		}
		catch(Exception e)
		{
			String strMessage = "服务器：" + getServer() +
					"，POST方式/test-batch，" +
					"测试批处理sql报错：" + e.toString();
			
			logger.error(strMessage);
			throw new Exception(strMessage);
		}
		
		return result;
	}
	
	@GetMapping(value="/generate-link")
	public Result generateLink()throws Exception
	{
		Result result = new Result();
		
		try
		{
			LoginUser loginUser = getUser();
			String strToken = exampleService.generateToken(loginUser);
			
			result.setServer(getServer());
			result.setCode(Constant.ResultCode.SUCCESS);
			result.setData(Constant.DEF_MY_CUSTOMER_PAGE + strToken + "&name=张&wealthAssetAumMin=500");
		}
		catch(Exception e)
		{
			String strMessage = "服务器：" + getServer() +
					"，GET方式/generateLink，" +
					"生成链接报错：" + e.toString();
			
			logger.error(strMessage);			
			throw new Exception(strMessage);
		}
		
		return result;
	}
}
